#!/usr/bin/env coffee

import Win from '../win.coffee'
import {top} from './recbar.coffee'
import platform from '@/config/platform.mjs'

{count_down} = Win

win = undefined

export 倒计时 = =>
  if win
    win.focus()
    return
  width = 240
  win = count_down {
    width
    height: width
    transparent: true
    resizable: false
    hasShadow: false
  }
  win.on 'close',=>
    win = undefined
    return
  win.setAlwaysOnTop(true,'screen-saver')
  win.on 'show',=>
    for i from BrowserWindow.getAllWindows()
      if not i.webContents.getURL().endsWith '/#main'
        #console.log i.webContents.getURL()
        i.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
    if platform == 'win32'
      moveTop = setInterval(
        =>
          if win
            win.moveTop()
          else
            clear()
        300
      )

      clear = =>
        clearInterval moveTop
        return

      win.on 'hide',clear
      win.on 'close',clear

    return

  return

export default {
  hide : =>
    win?.hide()
    return
  close : =>
    win?.close()
    top()
    return
}
